<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <!-- 当有人读取person的age属性时，get函数(getter)就会被调用，且返回值就是age的值 -->
    <!-- 当有人修改person的age属性时，set函数(setter)就会被调用，且会收到修改的具体值 -->
    <script>
        var book = {
            year: 2004,
        };
        var b = {};
        b.year = book.year;
        var year = book.year;
        Object.defineProperty(book, "year", {
            get: function() {
                return b.year;
            },

            set: function(newYear) {
                b.year = newYear;
            },
        });
        console.log(b);
        console.log(book.year);
        book.year = 2005;

        console.log(book.year);
    </script>
</body>

</html>